<!-- 维修派单 -->
<template>
	<view class="repair-dispatch-box">
		<navBar title="维修派单" goBackUrl="/pages/homePage/homePage" @goBack="goBack"></navBar>
		<view class="item-box title-item">
			<text class="txt" style="min-width: 100rpx;">工单号</text>
			<view style="padding-right: 50rpx;">
				<u--input type="number"  placeholder="请输入内容" v-model="orderNo" border="none" inputAlign="right"></u--input>
			</view>
		</view>
		<view class="item-box" @click="fnOpenDate">
			<text class="txt">截至日期</text>
			<view style="text-align: right;">
				<text>{{ endDate }}</text>
				<u-icon name="arrow-right" color="#e6e6e6" size="16"></u-icon>
			</view>
		</view>
		<view class="item-box" @click="show = true">
			<text class="txt team">施工班组</text>
			<view>
				<text>{{ team }}</text>
				<u-icon name="arrow-right" color="#e6e6e6" size="16"></u-icon>
			</view>
		</view>
		<!-- 选择日期 -->
		<u-datetime-picker @cancel="showDate=false" @confirm="confirm" :show="showDate" v-model="form.endDate"
			mode="date"></u-datetime-picker>
		<view class="footer-button">
			<view class="button-placeholder"></view>
			<view class="button-group">
				<button  @click="submitOrder" :loading="loading" :disabled="loading"  class="button-primary">提交</button>
			</view>
		</view>
		<u-picker :show="show" :columns="columns" keyName="name" @confirm="confirmTeam" @cancel="show = false"></u-picker>
	</view>
</template>

<script>
	import {
		diseaseDispatchOrder,
		getConstructionTeam
	} from '@/api/engineeringMaintenance/engineeringMaintenance.js'
	import mixins from '@/utils/mixins.js'
	export default {
		mixins: [mixins],
		data() {
			return {
				orderNo: '',
				showDate: false,
				endDate: '',
				diseaseIds: [],
				columns: [
					[]
				],
				show: false,
				team: '',
				form: {
					endDate: Number(new Date())
				},
				loading:false

			}
		},
		onLoad(params) {
			if (params && params.data) {
				this.diseaseIds = JSON.parse(params.data)
				this.pmInfo = JSON.parse(params.pmInfo)
			}
			this.getTeamList()
		},

		methods: {
			goBack() {
				uni.navigateBack()
			},
			fnOpenDate() {
				this.showDate = true
			},
			confirm(val) {
				console.log(val)
				this.$nextTick(() => {
					this.endDate = this.getDate(val.value)
				})
				this.showDate = false
			},
			confirmTeam(val) {
				console.log(val, '班组')
				this.team = val.value[0].name
				this.show = false
			},
			getTeamList() {
				getConstructionTeam({
					id: uni.getStorageSync('isOwner'),
				}).then(res => {
					this.columns = [res.result]
				})
			},
			submitOrder() {
				
				if (!this.team) return  uni.showToast({
					title: '请选择施工班组',
					icon: 'none'
				})
				this.loading = true
				// return
				diseaseDispatchOrder({
					diseaseIds: this.diseaseIds,
					orderNo: this.orderNo,
					endDate: this.endDate,
					team: this.team,
					pmId:this.pmInfo.pmId,
					pmName:this.pmInfo.pmName
				}).then(res => {
					if (res.success) {
						uni.showToast({
							title: res.message,
							icon: 'none',
							mask:true,
						})
						setTimeout(() => {
							uni.navigateBack()
							this.loading = false
						}, 1700)
						
					}else {
						this.loading = false
					}
				
				})
				
				
			}

		}
	}
</script>

<style lang="scss" scoped>
	.repair-dispatch-box {
		background-color: #f5f5f9;
		height: 100vh;
		/* #ifdef MP-WEIXIN */
			padding-top: 90rpx;
		/* #endif */
		.title-item {
			margin-top: 116rpx !important;
		}

		.item-box {

			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: white;
			padding: 28rpx 40rpx;
			margin: 20rpx 0;
			position: relative;
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #586981;
			
			.txt.team::before {
					content: "*";
					color: red;
				}
			// .txt {
			// 	margin-right: 150rpx;
			// }
		}

		.btn_box {
			height: 100rpx;

			.btn_group {
				display: flex;
				align-items: center;
				justify-content: space-between;
				position: fixed;
				bottom: 0;
				width: 100%;
			}
		}
	}
</style>
